package base.迭代器遍历;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class 迭代器 {
    public static void main(String[] args){
        //1.集合
        Collection<String> coll = new ArrayList<>();
        coll.add("hello world");
        coll.add("i come back");
        coll.add("now");
        //2.迭代器对象
        Iterator<String> it = coll.iterator();
        while (it.hasNext()){   //判断当前指标if有元素
            String str = it.next();    //获取元素 并移动指指针
            System.out.println(str);
        }
    }
}
